package com.service;

import com.bean.ZjCookHouse;
import com.mapper.repository.ZjCookHouseRepository;
import com.service.impl.ZjCookHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.UUID;

@Service
public class ZjCookHouseServiceImpl implements ZjCookHouseService {

    @Autowired
    private ZjCookHouseRepository zjCookHouseRepository;

    @Override
    public String initCookHouse(ZjCookHouse zjCookHouse) {
        //判断厨房名是否重复，如果重复，不能初始化
        int count = zjCookHouseRepository.countByName(zjCookHouse.getName());
        if(count>0){
            return "您的厨房名已存在，请重新输入";
        }
        zjCookHouse.setId(UUID.randomUUID().toString());
        zjCookHouse.setCreatetime(LocalDateTime.now());
        zjCookHouse.setChefid(zjCookHouse.getCreator());
        zjCookHouseRepository.save(zjCookHouse);
        return "初始化成功";
    }
}
